<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>水果详细</title>
    <script src="statics/jquery-1.6.2.min.js"></script>
    <script src="statics/layui.js"></script>
    <link rel="stylesheet" href="statics/css/layui.css" media="all">
</head>
<body>
<div style="padding-left: 600px">
    <form action="list" method="get">
        类别:<input type="text" name="type" lay-verify="type" value="${type}">
        品种:<input type="text" name="breed" lay-verify="breed" value="${breed}">
        <input type="submit" value="提交" class="layui-btn layui-btn-normal">
    </form>
</div>
<div><a href="add.jsp" style="padding-left: 800px;color: #1e9fff;">新增水果</a></div>
<table border="1" style="margin: 0 auto;border-collapse: collapse" class="layui-table">
    <thead>
    <tr style="text-align: center">
        <td lay-data="{field:'type', width:80, sort: true}">类别</td>
        <td lay-data="{field:'breed'}">品种</td>
        <td lay-data="{field:'area'}">产地</td>
        <td lay-data="{field:'weight'}">总重量（公斤）</td>
        <td lay-data="{field:'price'}">单价（元/公斤）</td>
        <td lay-data="{field:'cz'}">操作</td>
    </tr>
    </thead>
    <c:forEach var="fruit" items="${list}">
        <tr style="text-align: center">
            <td>${fruit.type}</td>
            <td>${fruit.breed}</td>
            <td>${fruit.area}</td>
            <td>${fruit.weight}</td>
            <td>${fruit.price}</td>
            <td>
                <a href="view?id=${fruit.fruitId}">详情</a>
                <a href="upd?id=${fruit.fruitId}">修改</a>
                <a href="javascript:void(0);" onclick="deleteFruit(${fruit.fruitId})">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>
<div style="padding-left: 750px;color: #1e9fff">
    共${count}条&nbsp;&nbsp;
    当前第${pageIndex}/${pageNum}页&nbsp;&nbsp;
    <c:if test="${pageIndex>1}">
        <a href="list?pageIndex=${pageIndex-1}" style="color: #1e9fff">上一页</a>
    </c:if>
    <c:if test="${pageIndex<pageNum}">
    <a href="list?pageIndex=${pageIndex+1}" style="color: #1e9fff">下一页</a></div>
</c:if>
<script>
    function deleteFruit(id) {
        if (confirm("确定要删除吗?")) {
            $.get('delete', 'id=' + id, function (data) {
                if (data == 'success') {
                    alert('删除成功');
                } else {
                    alert('删除失败');
                }
                location.reload();
            })
        }
    }
</script>
</body>
</html>
